package com.itheima.demo3;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Student {
    private long id;
    private String name;
    // 0 表示女，1 表示男
    private int sex;
    private LocalDateTime uploadTime;
    private String[] address;
    public static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static Student parseStudent(String str) {
        Student s = new Student();
        String[] info = str.split(",");
        s.setId(Long.parseLong(info[0]));
        s.setName(info[1]);
        s.setSex(info[2].equals("男") ? 1 : 0);
        s.setUploadTime(LocalDateTime.parse(info[3], dtf));
        s.setAddress(info[4].split("-"));
        return s;
    }
}
